{% extends 'index.html' %}
{% load filetransfers %}
{% load profiletags %}
{% block title %}Upload file to Blobstore{% endblock %}

{% block content %}

    <h2>Upload</h2>
    <p>
    <form action="{{ upload_url }}" method="POST" enctype="multipart/form-data">
      {% csrf_token %}
      {% render_upload_data upload_data %}
      <table>{{ form.as_p }}</table>
      <input type="submit" value="Upload" />
    </form>
    <p>

    Previous Images:
      {% for upload in uploads %}
         <div style="width:20%;float:left;">
              {% url pirate_sources.views.download_handler pk=upload.pk as fallback_url %}
              <img src="{{upload.url}}=s70-c"><br>
              {% if upload.private %}<i>Private</i>{% endif %}({{ upload.file.size|filesizeformat }})<br>

              <a href="{% firstof upload.file|public_download_url fallback_url %}">Download</a> | 
              <a href="{% url pirate_sources.views.change_avatar obj_pk=obj_pk new_pk=upload.pk ctype_pk=ctype_pk %}">Choose</a>

            {% if request.user.is_staff or request.user == upload.user %}
           
               | <a href="{% url pirate_sources.views.delete_handler pk=upload.pk ctype_pk=ctype_pk %}">Delete</a>

            {% endif %}
              
         </div>
        {% empty %} N/A
      {% endfor %}

    </p>

</div></div>
{% endblock %}
